<template>
    <BasePanel
        width="320px"
        height="100%"
        title="气"
        :class="{ 'base-panel-checked': globalStore.currentPopName === 'TestPop' }"
        @click="onClickPanel"
        style="cursor: pointer"
    >
        <template #rightTitle>
            <div @click.stop>
                <ElSelect
                    class="el-select-no-border"
                    style="width: 120px"
                    v-model="selectYear"
                    :suffixIcon="ArrowDownBold"
                >
                    <ElOption
                        v-for="item in config.yearSelectList"
                        :key="item"
                        :value="item"
                        :label="item"
                    />
                </ElSelect>
            </div>
        </template>
        <template #default>
            <div class="panel-content">
                <div class="item" v-for="item in listData" :key="item.label">
                    <div class="label">{{ item.label }}</div>
                    <div class="value-box">
                        <span class="value">{{ item.value }}</span>
                        <span class="unit">{{ item.unit }}</span>
                    </div>
                    <div class="target-box">
                        <span class="title">目标</span>
                        <span class="value">{{ item.targetValue }}{{ item.targetUnit }}</span>
                    </div>
                    <div class="compare-box">
                        <img class="trend-img" :src="item.compareImg" alt="" />
                        <div class="trend-info">
                            <span class="title">同比</span>
                            <div class="compare-value-box">
                                <span class="value" :style="{ color: item.compareColor }">
                                    {{ item.compareValue }}%
                                </span>
                                <SvgIcon
                                    class-name="icon-style"
                                    :color="item.compareColor"
                                    :name="item.compareIcon"
                                />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </template>
    </BasePanel>
</template>

<script setup lang="ts">
import { ArrowDownBold } from '@element-plus/icons-vue'
import BasePanel from '@/components/BasePanel/index.vue'
import SvgIcon from '@/components/SvgIcon/index.vue'
import { useGlobalStore } from '@/store/global'
import { getFpiAssetsFile } from '@/utils/tools'
import config from '@/config'
import dayjs from 'dayjs'

// 全局数据
const globalStore = useGlobalStore()

// 图片
const trendGreenDownImg = getFpiAssetsFile('global/big-trend-green-down.png')
const trendGreenUpImg = getFpiAssetsFile('global/big-trend-green-up.png')
// const trendBlueFlatImg = getFpiAssetsFile('global/big-trend-blue-flat.png')
// const trendYellowDownImg = getFpiAssetsFile('global/big-trend-yellow-down.png')
// const trendYellowUpImg = getFpiAssetsFile('global/big-trend-yellow-up.png')

// 点击面板
const onClickPanel = () => {
    globalStore.togglePopInfo({
        popName: 'TestPop',
        popData: null,
    })
}

// 选择的年份
const selectYear = ref(dayjs().year())

// 详细数据
const listData = shallowRef([
    {
        label: '优良率',
        value: 98.7,
        unit: '%',
        targetValue: 88.7,
        targetUnit: '%',
        compareValue: '7.7',
        compareImg: trendGreenUpImg,
        compareColor: 'rgba(0, 255, 115, 1)',
        compareIcon: 'up-arrow',
    },
    {
        label: 'PM2.5',
        value: 34,
        unit: 'μg/m3',
        targetValue: 32,
        targetUnit: 'μg/m3',
        compareValue: '6.8',
        compareImg: trendGreenDownImg,
        compareColor: 'rgba(0, 255, 115, 1)',
        compareIcon: 'down-arrow',
    },
])
</script>

<style lang="scss" scoped>
.panel-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;

    .item {
        height: 100%;
        width: auto;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;

        .label {
            font-size: 20px;
            font-weight: 700;
            line-height: 20px;
            height: 20px;
            color: rgba(255, 255, 255, 1);
        }

        .value-box {
            display: flex;
            align-items: flex-end;
            justify-content: center;
            gap: 4px;

            .value {
                font-family: Oswald;
                color: rgba(1, 254, 133, 1);
                font-size: 36px;
                line-height: 36px;
                height: 36px;
                font-weight: 400;
            }

            .unit {
                font-size: 18px;
                font-weight: 500;
                height: 18px;
                line-height: 18px;
                color: rgba(255, 255, 255, 1);
            }
        }

        .target-box {
            display: flex;
            align-items: center;
            gap: 4px;

            .title {
                font-size: 16px;
                font-weight: 500;
                height: 16px;
                line-height: 16px;
                color: rgba(255, 255, 255, 1);
            }

            .value {
                font-size: 20px;
                font-weight: 400;
                line-height: 20px;
                color: rgba(0, 255, 115, 1);
                height: 20px;
                font-family: Oswald;
            }
        }

        .compare-box {
            display: flex;
            align-items: center;
            gap: 4px;

            .trend-img {
                width: 64px;
                height: 48px;
                user-select: none;
            }

            .trend-info {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: flex-start;
                gap: 4px;

                .title {
                    font-size: 16px;
                    font-weight: 500;
                    line-height: 16px;
                    height: 16px;
                    color: rgba(255, 255, 255, 1);
                }

                .compare-value-box {
                    display: flex;
                    gap: 4px;
                    align-items: center;

                    .value {
                        font-family: Oswald;
                        font-size: 20px;
                        font-weight: 400;
                        height: 20px;
                        line-height: 20px;
                    }
                }
            }
        }
    }
}
</style>
